package com.keta.foundation.util;

import javax.servlet.http.HttpServletRequest;


public class AopUtil {

	// 用于存储每个线程的request请求
	private static final ThreadLocal<HttpServletRequest> LOCAL_REQUEST = new ThreadLocal<HttpServletRequest>();

	/**
	 * AOP拦截器执行方法前调用该方法，将请求放入ThreadLocal
	 */
	public static void putRequest(HttpServletRequest request) {
		LOCAL_REQUEST.set(request);
	}

	/**
	 * AOP拦截器执行方法后调用该方法，移除request
	 */
	public static void romeveRequest() {
		LOCAL_REQUEST.remove();
	}

	/**
	 * 将参数放入。
	 */
	public static void putArgs(String key,Object value) {
		HttpServletRequest request = LOCAL_REQUEST.get();
		request.setAttribute(key, value);
	}

	/**
	 * 得到参数
	 */
	public static Object getArgs(String key) {
		HttpServletRequest request = LOCAL_REQUEST.get();
		return  request.getAttribute(key);
	}

	

}
